<?php
/**
 * Created by PhpStorm.
 * User: shan
 * Date: 2016/11/17
 * Time: 15:49
 */
namespace  backend\models;

use yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;

class BannerSearch extends Model
{
    public $Page = 4;

    public function rules(){
        return [
        ];
    }

    public function attributeLabels()
    {
        return [];
    }

    public function search($params){
        $query = Banner::find()->where(['is_del'=>0]);
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => $this->Page,
            ]
        ]);
        $dataProvider->sort->defaultOrder = ['is_del' => SORT_DESC];
        if(!($this->load($params) && $this->validate())){
            return $dataProvider;
        }

    }


    protected function addCondition($query, $attribute, $partialMatch = false)
    {
        $value = $this->$attribute;
        if (trim($value) === '') {
            return;
        }
        if ($partialMatch) {
            $query->andWhere(['like', $attribute, $value]);
        } else {
            $query->andWhere([$attribute => $value]);
        }
    }

}